Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(decl/loader): set up JSON schema validation of the input #248

Merged
merged 5 commits into from
Dec 10, 2024

Conversation

ekoops
Copy link
Contributor

@ekoops ekoops commented Dec 6, 2024

What type of PR is this?

Uncomment one (or more) /kind <> lines:

/kind bug

/kind cleanup

/kind documentation

/kind tests

/kind feature

Any specific area of the project related to this PR?

Uncomment one (or more) /area <> lines:

/area commands

/area pkg

/area events

What this PR does / why we need it:
This PR introduces tests description validation through JSON schemas. Besides validation, JSON schemas allow to document the test description sections in an easily parsable format: this provides foundation for CLI commands aiming to expose sections documentation to the user.
In order to perform validation through JSON schemas, the loader has been modified to unmarshal tests description in two steps:

  • the first step performs the YAML-specific conversion of the description into a generic representation
  • the second step takes the generic representation and uses mapstructure to place the content in the right structures
    The JSON schema validation is performed, on the generic representation, between the two steps.

This PR also replaces the unmaintained go-yaml/yaml with goccy/go-yaml, and fixes the field bindings marshaling for nested fields.

The high number of line additions is due to the introduction of the JSON schemas.

Which issue(s) this PR fixes:

Fixes #

Special notes for your reviewer:

Signed-off-by: Leonardo Di Giovanna <[email protected]>
Co-authored-by: Aldo Lacuku <[email protected]>
@poiana poiana requested review from alacuku and FedeDP December 6, 2024 10:16
@poiana poiana added the size/XXL label Dec 6, 2024
@ekoops ekoops changed the title feat(decl/loader): set up two-steps unmarshaling via mapstructure and replace go-yaml/yaml wip: feat(decl/loader): set up two-steps unmarshaling via mapstructure and replace go-yaml/yaml Dec 6, 2024
@ekoops ekoops changed the title wip: feat(decl/loader): set up two-steps unmarshaling via mapstructure and replace go-yaml/yaml feat(decl/loader): set up JSON schema validation of the input Dec 6, 2024
ekoops and others added 4 commits December 9, 2024 16:57
Signed-off-by: Leonardo Di Giovanna <[email protected]>
Co-authored-by: Aldo Lacuku <[email protected]>
Unmarshal tests description in two steps: the first step performs
the YAML-specific conversion of the description into a generic
representation; the second step takes the generic representation
and uses mapstructure to place the content in the right structures.
Splitting the unmarshalling in two steps enables performing the
validation logic (through JSON schemas) before placing the content
in the corresponding structures.

Signed-off-by: Leonardo Di Giovanna <[email protected]>
Co-authored-by: Aldo Lacuku <[email protected]>
Replace go-yaml/yaml as it is practically not maintained anymore
and requires additional code to be written for marshalling
structures specifying 'inline' on any on their fields.

Signed-off-by: Leonardo Di Giovanna <[email protected]>
Co-authored-by: Aldo Lacuku <[email protected]>
Signed-off-by: Leonardo Di Giovanna <[email protected]>
Co-authored-by: Aldo Lacuku <[email protected]>
@poiana
Copy link

poiana commented Dec 10, 2024

[APPROVALNOTIFIER] This PR is APPROVED

This pull-request has been approved by: ekoops, leogr

The full list of commands accepted by this bot can be found here.

The pull request process is described here

Needs approval from an approver in each of these files:

Approvers can indicate their approval by writing /approve in a comment
Approvers can cancel approval by writing /approve cancel in a comment

@poiana
Copy link

poiana commented Dec 10, 2024

LGTM label has been added.

Git tree hash: c57554b747d7893c2f73ead5f4a60a3c7e4107cf

@poiana poiana merged commit ca62f90 into falcosecurity:declarative-testing Dec 10, 2024
5 of 6 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants